<template>
    <section class="wrapper">
      <myHeader :obj="myObj" @events="events(2)"></myHeader>
      <main>
        <mt-navbar v-model="selected" class="myNavbar">
          <mt-tab-item id="1" class="myNav">最新申请</mt-tab-item>
          <mt-tab-item id="2" class="myNav">正在进行</mt-tab-item>
          <mt-tab-item id="3" class="myNav">已结束</mt-tab-item>
        </mt-navbar>
        <mt-tab-container class="container" v-model="selected">
          <mt-tab-container-item class="item item_0308"  id="1">
            <div class="wrap wrapT_01" @scroll.passive="OrderData" >
              <div class="paddingT_10" v-for="item in listData" @click="toindentCourse(item.AppointmentOrderNo,item)">
                <div class="orderWrap">
                  <div class="orderItem">
                    <div class="faceWrap">
                      <i :style="{background:'url('+ item.HeadUrl + ') no-repeat center center', backgroundSize:'cover'}"></i>
                      <p>{{item.Name}}</p>
                    </div>
                    <div class="infoWrap">
                      <h2>{{item.Title}}</h2>
                      <h5 v-if="item.Describe">{{item.Describe}}</h5>
                      <h5>订单金额：￥{{item.Money.toFixed(2)}}</h5>
                      <h5>见面地点：{{item.Location?item.Location:"暂未确定"}}</h5>
                    </div>
                  </div>
                  <div class="fontWrap">
                    <span>约见时间：{{item.SMeetUpTime?item.SMeetUpTime.replace("T", " "):"暂未确定"}} — {{item.EMeetUpTime?item.EMeetUpTime.replace("T", " "):"暂未确定"}}</span>
                  </div>
                </div>
              </div>
            </div>
          </mt-tab-container-item>
          <mt-tab-container-item  class="item item_0308" id="2">
            <div class="wrap wrapT_02" @scroll.passive="OrderData" >
              <div class="paddingT_10" v-for="item in listData" @click="toindentCourse(item.AppointmentOrderNo,item)">
                <div class="orderItem">
                  <div class="faceWrap">
                    <i :style="{background:'url('+ item.HeadUrl + ') no-repeat center center', backgroundSize:'cover'}"></i>
                    <p>{{item.Name}}</p>
                  </div>
                  <div class="infoWrap">
                    <h2>{{item.Title}}</h2>
                    <h5 v-if="item.Describe">{{item.Describe}}</h5>
                    <div class="fontWrap">
                      <span>购买时间：{{item.UpdateTime?item.UpdateTime.slice(0,10):""}}</span>
                      <span>购买金额：￥{{item.Money?item.Money.toFixed(2):""}}</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </mt-tab-container-item>
          <mt-tab-container-item class="item item_0308" id="3">
            <div class="wrap wrapT_03" @scroll.passive="OrderData" >
              <div class="paddingT_10" v-for="item in listData" @click="toindentCourse(item.AppointmentOrderNo,item)">
                <div class="orderItem">
                  <div class="faceWrap">
                    <i :style="{background:'url('+ item.HeadUrl + ') no-repeat center center', backgroundSize:'cover'}"></i>
                    <p>{{item.Name}}</p>
                  </div>
                  <div class="infoWrap">
                    <h2>{{item.Title}}</h2>
                    <h5 v-if="item.Describe">{{item.Describe}}</h5>
                    <div class="fontWrap">
                      <span>购买时间：{{item.UpdateTime?item.UpdateTime.slice(0,10):""}}</span>
                      <span>购买金额：￥{{item.Money?item.Money.toFixed(2):""}}</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </mt-tab-container-item>
        </mt-tab-container>
      </main>
    </section>
</template>
<script>
import myHeader from './base/myHeader';
import myOrder from './base/myOrder';
import hgjSkip from '../assets/js/hgjSkip';
import API from '../assets/js/asktoses';
import { fetch } from '../assets/api';
import {Toast } from 'mint-ui';
export default {
  data () {
    return {
      myObj: {
        text: '申请列表'
      },
      selected: this.$route.query.index,
      typenum:0,
      listData:[],
      allListData:{},
      loginData:null,
      num:0,
      bol:false,
    }
  },
  created() {
    hgjSkip.skip().then(res =>{
      this.loginData = res;
      if(!this.selected){
        this.selected = "1";
      }else{
        switch(this.selected){
          case '2':
            this.UserMeetOrderData();
            break;
          case '3':
            this.UserMeetOrderData();
            break;
          default:
            this.UserMeetOrderData();
            break;
        }
      };
    });
  },
  methods: {
    events(i){
      if(i == 2) {
        history.back();
      }
    },
    OrderData(){
      let tagList = document.querySelector('.wrapT_0'+this.selected);
      let tagHeight = tagList.scrollHeight - tagList.clientHeight - 20;
      let tagScroll = tagList.scrollTop;
      if(tagHeight <= tagScroll  && this.bol) {
        this.bol = false;
        this.UserMeetOrderData()
      }
    },
    async UserMeetOrderData(){
      this.num++;
      this.typenum = this.selected-1?this.selected-1:0;
      const res = await fetch(API.getUserMeetOrderData,{
        ...this.loginData[1],
        Type:this.typenum,
        PageIndex:this.num
      });     
      this.allListData = res.Result.OrderList;
      this.allListData.forEach(item => {
        this.listData.push(item)
      });
      if(this.allListData.length == 10){
        this.bol = true;
      } else {
        this.bol = false;
      }
    },
    toindentCourse(OrderNo,item) {
      switch(item.State){
        case 1:
          this.$router.push({path:"confirm",query:{AppointmentOrderNo:OrderNo}});
          break;
        case 7:
          this.$router.push({path:"confirm",query:{AppointmentOrderNo:OrderNo}});
          break;
        case 2:
          this.$router.push({path:"agreeSee",query:{AppointmentOrderNo:OrderNo,exper:true}});
          break;
        case 8:
          this.$router.push({path:"agreeSee",query:{AppointmentOrderNo:OrderNo,exper:true}});
          break;
        case 30:
          this.$router.push({path:"agreeSee",query:{AppointmentOrderNo:OrderNo,exper:true}});
          break;
        case 3:
          this.$router.push({path:"agreeSee",query:{AppointmentOrderNo:OrderNo,state:3,exper:true}});
          break;
        case 9:
          this.$router.push({path:"agreeSee",query:{AppointmentOrderNo:OrderNo,state:3,exper:true}});
          break;
        case 4:
          this.$router.push({path:"agreeSee",query:{AppointmentOrderNo:OrderNo,state:3,exper:true}});
          break;
        case 6:
          this.$router.push({path:"gradeFinish",query:{AppointmentOrderNo:OrderNo,num:2}});
          break;
        case 5:
          this.$router.push({path:"gradeFinish",query:{AppointmentOrderNo:OrderNo,num:2}});
          break;
      }
    },
  },
  watch: {
    selected(val) {
      this.num = 0;
      this.listData.length = 0;
      this.UserMeetOrderData();
      this.$router.replace({path:'/reqList',query:{index:val}});
    }
  },
  components: {
    myHeader,
    myOrder
  }
}

</script>
<style lang="less">
  .wrapper {
    width: 3.75rem;
    height: 100%;
    main {
      width: 3.75rem;
      height: 100%;
      padding-top: .44rem;
      position: absolute;
      top: 0;
      left: 0;
      overflow-y: auto;
      box-sizing: border-box;
      .wrap{
        width: 100%;
        height: 100%;
        overflow: scroll;
        padding-bottom:0.1rem;
      }
      .container {
        padding-top: .94rem;
        height: 100%;
        width: 3.75rem;
        position: absolute;
        top: 0;
        box-sizing: border-box;
        >div {
          height: 100%;
        }
        .item {
          padding-top: 0.85rem;
          height: 100%;
          width: 3.75rem;
          position: absolute;
          top: 0;
          box-sizing: border-box;
          .paddingT_10 {
            padding-top: .1rem;
            .orderWrap {
              margin: 0 auto;
              width: 3.5rem;
              background: white;
              padding-bottom: .1rem;
              .fontWrap{
                padding-top: .1rem;
                margin-top: .1rem;
                padding-left: .1rem;
                border-top: 1px solid #ddd;
                span{
                  font-size: .12rem;
                  color: #B3B3B6;
                  &:nth-of-type(2){
                    margin-left: .2rem;
                  }
                }
              }
            }
            .orderItem{
              padding: 0 .1rem;
              border-radius: .04rem;
              display: -webkit-box;
              display: -ms-flexbox;
              display: flex;
              padding-top: .1rem;
              position: relative;
              .btdelete{
                display: inline-block;
                border-radius: .03rem;
                position: absolute;
                top: .12rem;
                right: .12rem;
                color: #5679FF;
                font-size: .14rem;
              }
              .faceWrap{
                i{
                  display: block;
                  height: .65rem;
                  width: .65rem;
                  border-radius: 50%;
                }
                p{
                  text-align: center;
                  font-size: .12rem;
                  color: #333;
                  margin-top: .05rem;
                }
              }
              .infoWrap{
                padding-left: .1rem;
                padding-top: .1rem;
                h2{
                  color: #333;
                  font-size: .14rem;
                  font-weight: normal;
                  display: -webkit-box;
                  -webkit-box-orient: vertical;
                  -webkit-line-clamp:1;
                  overflow: hidden;
                }
                h5{
                  display: -webkit-box;
                  -webkit-box-orient: vertical;
                  -webkit-line-clamp:1;
                  overflow: hidden;
                  margin: 0.1rem 0 0;
                  font-size: .12rem;
                  color: #B3B3B6;
                  font-weight: normal;
                }
              }
            }
          }
        }
        .item_0308 {
          overflow-y: auto;
        }
      }
    }
  }

</style>
<style>
  .myNavbar {
    display: block;
    justify-content: space-around;
    overflow: hidden;
    padding: 0 .15rem;
    box-sizing: border-box;
    background: #FAFAFA;
    position: relative;
    z-index: 2;
  }
  .mint-navbar .myNav {
    display: block;
    width: .85rem;
    float: left;
    margin: 0 .15rem;
  }
  .mint-navbar .is-selected {
    border-bottom: 3px solid #557AFF!important;
  }
  .mint-navbar .myNav .mint-tab-item-label {
    font-size: .14rem;
  }
  .mint-navbar .is-selected .mint-tab-item-label {
    color: #557AFF;
    font-weight: 600;
    font-size: .14rem;
  }
</style>
